﻿using MengLin.OOP.DesignPattern.FactoryMethod;
using MengLin.OOP.DesignPattern.Entity;
using MengLin.OOP.DesignPattern.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MengLin.OOP.DesignPattern.FactoryMethod.Client
{
    class Program
    {
        static void Main(string[] args)
        {
            User newUser = new User();
            newUser.Id = 123456;
            newUser.Name = "张三";

            #region 传统写法-上端依赖(直接调用/指定)下端对象，会有依赖
            //{
            //    OrcalUserService orcalUserService = new OrcalUserService();
            //    orcalUserService.CreateUser(newUser);
            //}
            //{
            //    SqlServerUserService sqlServerUserService = new SqlServerUserService();
            //    sqlServerUserService.CreateUser(newUser);
            //}
            //{
            //    int[] array = new int[2];
            //    array[0] = 1;
            //    array[1] = 2;
            //    MySqlUserService mySqlUserService = new MySqlUserService(1, "管理员", array);
            //    mySqlUserService.CreateUser(newUser);
            //}
            #endregion

            //相对于简单工厂
            #region 工厂模式写法
            {
                IFactory orcalFactory = new OrcalFactory();
                IUserService iUserService = orcalFactory.CreateInstance();
                iUserService.CreateUser(newUser);
                iUserService.GetUser(123456);
            }
            {
                IFactory sqlServerFactory = new SqlServerFactory();
                IUserService iUserService = sqlServerFactory.CreateInstance();
                iUserService.CreateUser(newUser);
                iUserService.GetUser(123456);
            }
            //注意：这里我的动作是增加
            {
                IFactory mySqlFactory = new MySqlFactory();
                IUserService iUserService = mySqlFactory.CreateInstance();
                iUserService.CreateUser(newUser);
                iUserService.GetUser(123456);
            }
            //自定义
            {
                IFactory mySqlFactory = new MySqlFactoryExtend();
                IUserService iUserService = mySqlFactory.CreateInstance();
                iUserService.CreateUser(newUser);
                iUserService.GetUser(123456);
            }
            #endregion

            Console.ReadKey();
        }
    }
}
